package com.hui.auth.dao.sql;



import com.hui.auth.entity.Entity;

import java.util.List;

/**
 * Created by hujia on 2017/3/13.
 */
public class CommonSQLProvider {
    public <T extends Entity> String queryBy(final T item) {
        return new DynamicSQL() {
            {
                SELECT("*");
                FROM(item.table());
                WHERE_OBJECT(item);
            }
        }.toString();
    }

    public String queryByIds(List<Integer> ids, String table) {
        return new DynamicSQL() {
            {
                SELECT("*");
                FROM(table);
                WHERE_LIST(ids, "id");
            }
        }.toString();
    }

    public <T extends Entity> String insert(final T item) {
        return new DynamicSQL() {
            {
                INSERT_INTO(item.table());
                BUILD_VALUES(item);
            }
        }.toString();
    }

    public <T extends Entity> String update(final T item) {
        return new DynamicSQL() {
            {
                UPDATE(item.table());
                BUILD_SET(item);
                WHERE("id = #{id}");
            }
        }.toString();
    }
}
